Skip to content

Make the state wipe after battery event configurable - #54

Open
lipusal wants to merge 2 commits into
hardwarehaven:mainfrom
lipusal:feat/configurable-state-reset
Open

Make the state wipe after battery event configurable#54
lipusal wants to merge 2 commits into
hardwarehaven:mainfrom
lipusal:feat/configurable-state-reset

Conversation

@lipusal

@lipusal lipusal commented Sep 7, 2026

Copy link
Copy Markdown

In its current state, after the host running wolnut goes down from a drained battery, on restart it will wipe its state file of hosts that were online before the outage. So in a situation like this, wolnut won't send WoL packets to hosts, i.e. nothing will be brought back online.

Other forks change this behavior, and #47 removes it altogether. This PR does similar changes, the main difference being that it makes this behavior configurable - by default, it will behave as it does now (i.e. state is wiped after a reset), but it can be changed to persist the state file. Happy to discuss with @JcMinarro where we want to go between the 2 PRs.

The change

A new top-level boolean config option, reset_state_on_resume:

reset_state_on_resume: true   # default
  • true (default) — unchanged behavior.
  • false — the loaded state is preserved and on_battery = True is set instead. The main loop then takes the normal power restoration branch on the first OL reading, with was_online_before_battery intact, and wakes the clients that were actually up before the outage. If the UPS is still reporting OB at boot, wolnut simply waits for power to come back.

Added tests, and all 53 tests pass.

Disclaimer: 🤖 Generated with Claude Code

lipusal and others added 2 commits September 7, 2026 12:57
When wolnut starts and finds `ups_on_battery` set in the state file, it
logs "resuming from a UPS battery event" and immediately calls
`ClientStateTracker.reset()`, which clears `was_online_before_battery`
for every client. The restoration branch then skips every client with
"was not online before power loss", so no WOL packet is ever sent.

That only matters when wolnut's own host was shut down by the outage --
exactly the case where the state file is the only surviving record of
who was online. When wolnut stays up through the outage the in-memory
path is used and the wipe is harmless, which is why this has gone
unnoticed.

Make the wipe configurable via a new top-level `reset_state_on_resume`
boolean. It defaults to `true`, which is byte-for-byte the current
behaviour, so upgrading without touching the config changes nothing.
When set to `false`, the loaded state is kept and `on_battery` is set
instead: the main loop then takes the normal power restoration branch on
the first "OL" reading with `was_online_before_battery` intact, and does
not re-snapshot an offline fleet if the UPS is still reporting "OB".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KTXBZgVFTjfbQd1Npk8Sgf
Add the new top-level option to the configuration guide and the example
config, including when you would want to turn it off.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KTXBZgVFTjfbQd1Npk8Sgf
@lipusal

lipusal commented Sep 7, 2026

Copy link
Copy Markdown
Author

Alright, Claude clearly went ham with this PR description, let me simplify it
Edit: Done

@lipusal lipusal changed the title feat: make the state wipe on resume configurable (reset_state_on_resume) Make the state wipe after drained battery configurable Sep 7, 2026
@lipusal lipusal changed the title Make the state wipe after drained battery configurable Make the state wipe after battery event configurable Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant